<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>充值</title>
    <style>
        div {
            position: absolute;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }
        table,tr,th,td{
            border: 1px solid #5fbdcb;
        }
        table{
            border-collapse: collapse;
        }
    </style>
</head>
<body>
<div>
    请输入你要充值的金额<label for="money"></label><input type="number" name="money" id="money" placeholder="请填写金额" min="0">
    <input type="button" value="提交"><br>
    <a href="UserPage.jsp">返回</a>
</div>
</body>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script>
    $(function () {
        $(':button').on('click', function () {
            $.ajax({
                url: "http://localhost:8080/user.do",
                type: "post",
                data: {
                    money:$('#money').val(),
                    method: 'recharge'
                },
                dataType: "text",
                success: function (data) {
                    if (data === 'ok') {
                        alert('充值成功！');
                        window.location.href = 'UserPage.jsp';
                    }
                    if (data === 'error') {
                        alert('充值失败！');
                    }
                }
            })
        })
    })
</script>
</html>
